﻿
 function MainViewModel() {
     var self = this;
     self.route = ko.observable("home");
     self.admin = ko.observable(false);
     self.render = ko.observable("home");
     self.logOn = new LogOnViewModel(self);
     self.profile = new ViewModel(self, auth, username);
     self.company = new CompanyViewModel(self, auth, username);
     self.position = new PositionViewModel(self);
     self.category = new CategoryViewModel(self);
     self.education = new EducationViewModel(self);
     self.country = new CountryViewModel(self);
     self.technology = new TechnologyViewModel(self);
     self.language = new LanguageViewModel(self);
     self.folder = new MessageFolderViewModel(self);
     self.bookmark = new BookmarkViewModel(self);
     self.pageSizeDefault = 30;
     self.pageIndexDefault = 0;
     self.ajaxLoading = ko.observable(false);

     self.pageSizeChoicesProfiles = ko.observableArray(["30", "60", "90"]);
     self.pageSizeChoicesMyProfiles = ko.observableArray(["3", "6", "9", "30", "60", "90"]);

     //AJAX LOADING
     $.ajaxSetup({
         cache: false,
         beforeSend: function() {
             self.ajaxLoading(true);
         },
         complete: function() {
             self.ajaxLoading(false);
         },
         success: function() {
         }
     });

     //JQUERY UI AUTOCOMPLETE
     self.autocompleteKeywords = function() {

         $("#keywordsExperts").autocomplete({
             source: function(request, response) {
                 $.ajax({
                     url: "ExpertProfile/GetTagItems",
                     dataType: "json",
                     data: {
                         searchTerm: request.term
                     },
                     success: function(data) {
                         //var queryResult = Enumerable.From(data).Where(function (x) { return x.Description.indexOf(item.Description) !== -1; }).ToArray();
                         response($.map(data, function(item) {

                             return {
                                 //label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
                                 label: item.Description,
                                 value: item.Type + item.Id
                             };
                         }));
                     }
                 });
             },
             minLength: 2,
             select: function(event, ui) {
                 var x = 1;
                 appendAutocomplete(ui.item ?
                     "Selected: " + ui.item.label :
                     "Nothing selected, input was " + this.value);
                 var id = ui.item.value.substring(1);
                 var type = ui.item.value.substring(0, 1);
                 // var description = ui.item.label;

                 // self.searchModel.tags.push({ id: id, title: title, type: type });


                 if (type == 'i') {
                     self.profile.profileAdvancedSearch().IndustryIds().push(id);
                 }
             }
             //                open: function() {
                 //                    $(this).removeClass("ui-corner-all").addClass("ui-corner-top");
                 //                },
                 //                close: function() {
                 //                    $(this).removeClass("ui-corner-top").addClass("ui-corner-all");
                 //                }
         });
     };


     //INDUSTRIES
     self.availableIndustries = ko.observableArray([]);
     self.availableIndustriesWithoutAll = ko.observableArray([]);
     self.
         loadIndustries = function() {
             $.ajax({
                 url: "/api/Industry/List",
                 type: 'POST',
                 dataType: 'json',
                 data: { },
                 contentType: "application/json",
                 success: function(industries) {
                     self.availableIndustriesWithoutAll(industries);
                     var industriesNew = industries.slice();
                     self.availableIndustries(industriesNew);
                     self.availableIndustries().unshift({
                         Id: -1,
                         Description: "All Industries"
                     });
                 }
             });
         };
     //COUNTRIES
     self.availableCountries = ko.observableArray([]);
     self.availableCountriesWithoutAll = ko.observableArray([]);
     self.loadCountries = function() {
         $.ajax({
             url: "/api/Country/List",
             type: 'POST',
             dataType: 'json',
             data: { },
             contentType: "application/json",
             success: function(countries) {
                 self.availableCountriesWithoutAll(countries);
                 var countriesNew = countries.slice();
                 self.availableCountries(countriesNew);
                 self.availableCountries().unshift({
                     Id: -1,
                     Description: "All Countries"
                 });
             }
         });
     };

     //CATEGORIES and SUBCATEGORIES
     self.category = ko.observable(new Category({ }));
     self.availableCategories = ko.observableArray([]);
     self.loadCategories = function() {
         $.ajax({
             url: "/api/Category/ListChildCategories",
             type: 'POST',
             dataType: 'json',
             data: ko.toJSON(self.category()),
             contentType: "application/json",
             success: function(categories) {
                 var categoriesNew = categories.slice();
                 self.availableCategories(categoriesNew);
                 self.availableCategories().unshift({
                     Id: -1,
                     Description: "All Categories"
                 });
             }
         });

     };
     self.availableSubcategories = ko.observableArray([]);
     self.loadSubcategories = function(selectedCategoryId) {
         var parentCategory = $.Enumerable.From(self.availableCategories()).SingleOrDefault(null, function(x) {
             return selectedCategoryId === x.Id;
         });
         $.getJSON("/ExpertProfile/GetChildCategories", parentCategory, function(categories) {
             self.availableSubcategories(categories);
             self.availableSubcategories().unshift({
                 Id: -1,
                 Description: "All Subcategories"
             });
         });
     };
     //RELOAD SUBCATEGORIES WHEN CATEGORY SELECTION CHANGED
     //self.checkSubcategoriesExperts = ko.computed(function() {
     //    var selectedCategoryIdExperts = self.profile.selectedCategoryId();
     //    self.loadSubcategories(selectedCategoryIdExperts);
     //});
     //self.checkSubcategoriesCompanies = ko.computed(function() {
     //    var selectedCategoryIdCompanies = self.company.selectedCategoryId();
     //    self.loadSubcategories(selectedCategoryIdCompanies);
     //});
     //self.checkSubcategoriesPositions = ko.computed(function() {
     //    var selectedCategoryIdPositions = self.position.selectedCategoryId();
     //    self.loadSubcategories(selectedCategoryIdPositions);
     //});

     //CENTER MODALS
     self.centerSignInModal = function() {
         $('#SignInDialog').on('shown', function() {
             var modal;
             modal = $(this);
             modal.css('margin-top', (modal.outerHeight() / 2) * -1).css('margin-left', (modal.outerWidth() / 2) * -1);
             return this;
         });
     };
     self.centerRegisterModal = function() {
         $('#RegisterDialog').on('shown', function() {
             var modal;
             modal = $(this);
             modal.css('margin-top', (modal.outerHeight() / 2) * -1).css('margin-left', (modal.outerWidth() / 2) * -1);
             return this;
         });
     };
     self.centerDeleteProfileModal = function() {
         $('#DeleteDialog').on('shown', function() {
             var modal;
             modal = $(this);
             modal.css('margin-top', (modal.outerHeight() / 2) * -1).css('margin-left', (modal.outerWidth() / 2) * -1);
             return this;
         });
     };
     self.centerDeleteCompanyModal = function() {
         $('#DeleteCompanyDialog').on('shown', function() {
             var modal;
             modal = $(this);
             modal.css('margin-top', (modal.outerHeight() / 2) * -1).css('margin-left', (modal.outerWidth() / 2) * -1);
             return this;
         });
     };
     self.centerDeletePositionModal = function() {
         $('#DeletePositionDialog').on('shown', function() {
             var modal;
             modal = $(this);
             modal.css('margin-top', (modal.outerHeight() / 2) * -1).css('margin-left', (modal.outerWidth() / 2) * -1);
             return this;
         });
     };


     //ADVANCED SEARCH
     self.advancedSearch = function() {
         if (self.searchModel() == "Experts") {
             self.expertsAdvancedSearch(true);
             self.companiesAdvancedSearch(false);
             self.positionsAdvancedSearch(false);
             if (self.route() != "experts") {

                 self.profile.generateRoute();

             }
         } else if (self.searchModel() == "Companies") {
             self.expertsAdvancedSearch(false);
             self.companiesAdvancedSearch(true);
             self.positionsAdvancedSearch(false);
             if (self.route() != "companies") {
                 self.company.generateRoute();
             }
         } else if (self.searchModel() == "Positions") {
             self.expertsAdvancedSearch(false);
             self.companiesAdvancedSearch(false);
             self.positionsAdvancedSearch(true);
             if (self.route() != "Positions") {
                 self.position.generateRoute();
             }
         }
         self.profile.profileViewMode("advancedSearch");
         self.company.companyViewMode("advancedSearch");
         self.position.PositionViewMode("advancedSearch");
         self.profile.resetTagsLists();
         self.company.resetTagsLists();
         self.position.resetTagsLists();
         self.profile.profileAdvancedSearch(new ExpertProfileAdvancedSearch({ }));
         self.company.companyAdvancedSearch(new CompanyProfileAdvancedSearch({ }));
         self.position.positionAdvancedSearch(new PositionAdvancedSearch({ }));
     };
     self.advancedSearchExperts = function() {
         self.searchModel("Experts");
         self.advancedSearch();
     };
     self.advancedSearchCompanies = function() {
         self.searchModel("Companies");
         self.advancedSearch();
     };
     self.advancedSearchPositions = function() {
         self.searchModel("Positions");
         self.advancedSearch();
     };

     //SIMPLE SEARCH
     self.simpleSearch = function() {
         if (self.searchModel() == "Experts") {
             self.profile.simpleSearch();
         } else if (self.searchModel() == "Companies") {
             self.company.simpleSearch();
         } else if (self.searchModel() == "Positions") {
             self.position.simpleSearch();
         }
     };

     //SEARCH by what
     self.searchModel = ko.observable("Experts");
     self.setExpertsSearch = function() {
         self.searchModel("Experts");
     };
     self.setCompaniesSearch = function() {
         self.searchModel("Companies");
     };
     self.setPositionsSearch = function() {
         self.searchModel("Positions");
     };
     self.expertsSearchVisible = ko.observable(true);
     self.companiesSearchVisible = ko.observable(false);
     self.positionsSearchVisible = ko.observable(false);
     self.expertsAdvancedSearch = ko.observable(false);
     self.companiesAdvancedSearch = ko.observable(false);
     self.positionsAdvancedSearch = ko.observable(false);
     self.observeSearchModel = ko.computed(function() {
         var model = self.searchModel();
         if (model == "Experts") {
             self.expertsSearchVisible(true);
             self.companiesSearchVisible(false);
             self.positionsSearchVisible(false);
             self.profile.setDefaultSidebarIds();
         } else if (model == "Companies") {
             self.expertsSearchVisible(false);
             self.companiesSearchVisible(true);
             self.positionsSearchVisible(false);
             self.company.setDefaultSidebarIds();
         } else if (model == "Positions") {
             self.expertsSearchVisible(false);
             self.companiesSearchVisible(false);
             self.positionsSearchVisible(true);
             self.position.setDefaultSidebarIds();
         }
     });


     //COMPANIES
     self.availableCompanies = ko.observable([]);
     self.selectedCompany = ko.observable();
     self.loadCompanies = function() {
         $.getJSON("/Home/GetJsonCompanies", function(allData) {
             self.availableCompanies(allData);
         });
     };
     //EDUCATION
     self.availableSearchEducations = ko.observable([]);
     self.excludedSearchEducations = ko.observable([]);

     self.loadEducations = function() {
         $.getJSON("/ExpertProfile/GetJsonEducation", function(allData) {
             self.availableSearchEducations(allData);
         });
     };

     self.addSearchEducation = function(education) {
         self.profileAdvancedSearch().Educations.push(education);
     };
     self.removeSearchEducation = function(education) {
         self.profileAdvancedSearch().Educations.remove(education);
     };
     //CATEGORIES
     self.availableCategories = ko.observableArray([]);
     self.breadCrumbCategories = ko.observableArray([{ Id: -1, Description: "Start" }]);
     self.getChildCategories = function(category) {
         $.getJSON('/ExpertProfile/GetChildCategories', category, function(result) {
             self.availableCategories(result);
         });
     };
     self.resetCategories = function() {
         self.getChildCategories(null);
         self.breadCrumbCategories([{ Id: -1, Description: "Start" }]);
     };
     self.selectBreadCrumbCategory = function(category) {
         var index = 0;
         var count = self.breadCrumbCategories().length;

         // find the index of the selected bread crumb category
         for (; index < count; index++) {
             if (self.breadCrumbCategories()[index].Id == category.Id) {
                 break;
             }
         }
         var deleteCount = count - index - 1;
         //returns the selected category
         if (deleteCount > 0) {
             self.breadCrumbCategories.splice(index + 1, deleteCount);
         }
         self.getChildCategories(category);
     };

     self.addSearchCategory = function(category) {
         if (category.IsLeaf) {
             var foundCategory = ko.utils.arrayFirst(self.profileAdvancedSearch().Categories(), function(item) {
                 return item.Id == category.Id;
             });
             if (!foundCategory) {
                 self.profileAdvancedSearch().Categories.push(category);

             }
         } else {
             self.breadCrumbCategories.push(category);
             self.getChildCategories(category);
         }
     };

     self.removeSearchCategory = function(category) {
         self.profileAdvancedSearch().Categories.remove(category);
     };
     //TECHNOLOGY SKILLS
     self.selectedTechnology = ko.observable();
     self.availableTechnologies = ko.observable();
     self.loadTechnologies = function() {
         $.getJSON("/ExpertProfile/GetJsonTechnologies", function(allData) {
             self.availableTechnologies(allData);
         });
     };
     self.addSearchTechnologySkill = function() {
         var level = $("#profileAvailableSearchTechnologiesLevel").val();
         var experience = $("#profileAvailableSearchTechnologiesExperience").val();
         var newtechnologySkill = new TechnologySkill({
             TechnologyName: self.selectedTechnology().Name,
             TechnologyId: self.selectedTechnology().Id,
             Level: level,
             Experience: experience
         });
         var foundTechnologySkill = ko.utils.arrayFirst(self.profileAdvancedSearch().TechnologySkills(), function(item) {
             return item.TechnologyName == newtechnologySkill.TechnologyName();
         });
         if (!foundTechnologySkill) {
             self.profileAdvancedSearch().TechnologySkills.push(newtechnologySkill);
         }
     };
     self.removeSearchTechnologySkill = function(technologySkill) {
         self.profileAdvancedSearch().TechnologySkills.remove(technologySkill);
     };

     //LANGUAGE SKILLS
     self.availableLanguages = ko.observable();
     self.loadLanguages = function() {
         $.getJSON("/ExpertProfile/GetJsonLanguages", function(allData) {
             self.availableLanguages(allData);
         });
     };
     self.selectedLanguage = ko.observable(null);
     self.addSearchLanguageSkill = function() {
         var level = $("#profileAvailableSearchLanguagesLevel").val();
         var newlanguageSkill = new LanguageSkill({
             LanguageName: self.selectedLanguage().Description,
             LanguageId: self.selectedLanguage().Id,
             Level: level
         });
         var foundLanguageSkill = ko.utils.arrayFirst(self.profileAdvancedSearch().LanguageSkills(), function(item) {
             return item.LanguageName == newlanguageSkill.LanguageName();
         });
         if (!foundLanguageSkill) {
             self.profileAdvancedSearch().LanguageSkills.push(newlanguageSkill);
         }
     };
     self.removeSearchLanguageSkill = function(languageSkill) {
         self.profileAdvancedSearch().LanguageSkills.remove(languageSkill);
     };

     self.industriesSource = ko.observableArray([]);

     //SET/RESET PARAMETERS
     self.setMyListProfileParameters = function() {
         self.profile.workingProfileId(null);
         self.profile.flagId(null);
         self.profile.profileViewMode("myList");
         self.profile.flagMode("myList");
         self.profile.currentPage(self.pageIndexDefault);
         self.profile.pageSize(self.pageSizeDefault);
         self.profile.industryId(0);
         self.profile.categoryId(0);
         self.profile.technologyId(0);
         location.hash = "#/Experts/";
     };
     self.setListProfileParameters = function() {
         self.profile.workingProfileId(null);
         self.profile.flagId(null);
         self.profile.profileViewMode("list");
         self.profile.flagMode("list");
         self.profile.currentPage(self.pageIndexDefault);
         self.profile.pageSize(self.pageSizeDefault);
         self.profile.industryId(0);
         self.profile.categoryId(0);
         self.profile.technologyId(0);
         location.hash = "#/Experts/";
     };


     //INIT
     self.init = function() {
         self.loadIndustries();
         self.loadCountries();
         self.loadCategories();
         //self.centerSignInModal();
         //self.centerRegisterModal();
         //self.centerDeleteProfileModal();
         //self.centerDeleteCompanyModal();
         //self.centerDeletePositionModal();
         //self.profile.centerCategorySkillsProfileModal();
         //self.profile.centerTechnologySkillsProfileModal();
         //self.profile.centerLanguageSkillsProfileModal();
         //self.profile.centerEducationSkillsProfileModal();
         //self.profile.centerContactProfileModal();
         self.profile.loadEmploymentTypes();
         self.profile.loadAvailabilityStatuses();
         self.profile.loadLevels();
         self.profile.loadExperiences();
         //self.company.autocompleteKeywords();
         //self.profile.autocompleteIndustries();
         //self.profile.autocompleteCategories();
         //self.profile.autocompleteTechnologies();
         //self.profile.autocompleteCountries();
         //self.profile.autocompleteEducations();
         //self.profile.autocompleteLanguages();
         //self.profile.autocompleteKeywords();
         //self.profile.autocompleteEmploymentTypes();
         //self.profile.autocompleteAvailabilityStatuses();
         //self.company.autocompleteIndustries();
         //self.company.autocompleteCountries();
         //self.company.autocompleteCategories();
         //self.company.autocompleteTechnologies();
         //self.position.autocompleteCountries();
         //self.position.autocompleteCategories();
         //self.position.autocompleteTechnologies();
         //self.position.autocompleteTechnologiesEdit();
         //self.position.autocompleteCompanies();
         //self.position.autocompleteIndustries();
         //self.position.autocompleteKeywords();
         //self.position.autocompleteEmploymentTypes();
         //self.folder.autocompleteRecipients();
         //self.folder.autocompleteSenders();
         //self.profile.autocompleteTechnologiesEditMode();
         //self.company.autocompleteTechnologiesEditMode();
         //self.position.autocompleteTechnologiesEditMode();
     };
     self.init();

     //SAMMY ROUTES
     Sammy(function() {
         this.element_selector = '#mainBody';

         this.get('#/', function() {
             $('#ajaxLoading').hide();
             self.route("home");
             var activationKey = this.params.activationKey;
             if (activationKey != null) {
                 self.logOn.activateUser(activationKey);
             }
             self.render("home");
         });

         this.get('#/Confirmation', function() {
             self.route("confirmation");
             self.render("confirmation");
         });

         this.get('#/Profiles', function() {
             self.route("profiles");
             if (!self.logOn.createProfilesVisible()) {
                 self.profile.setMyListRoute();
                 self.company.setMyListRoute();
                 self.position.setMyListRoute();
                 if (self.profile.profiles().length == 0 && self.company.companies().length == 0 && self.position.positions().length == 0) {
                     self.logOn.createProfilesVisible(true);
                 }
             }
             self.render("profiles");
         });

         this.get("#/Experts/?", function() {
             self.route("experts");
             self.searchModel("Experts");
             //if we're not in adavnced search mode then set the params from the route
             if (self.profile.profileViewMode() != "advancedSearch") {
                 self.profile.resetSearchModel();
                 var id = this.params.id;
                 var mode = this.params.mode;
                 var pageIndex = this.params.pageIndex;
                 var pageSize = this.params.pageSize;
                 var countryId = this.params.countryId;
                 var categoryId = this.params.categoryId;
                 var industryId = this.params.industryId;
                 var technologyId = this.params.technologyId;
                 self.profile.workingProfileId(id);
                 //MODE
                 // if mode is not defined in route then profileViewMode has value: "list"
                 if (!mode) {
                     self.profile.profileViewMode("list");
                 } else {
                     self.profile.profileViewMode(mode);
                 }
                 //if for example u go to mylist from menu then to list from menu and go back,u haven't clicked on menu to set UserId to 1,so u have to set that here in the route
                 if (self.profile.profileViewMode() == "myList") {
                     self.profile.profileAdvancedSearch().UserId(1);
                 }
                 self.profile.profileAdvancedSearch().PageIndex(pageIndex ? pageIndex : self.pageIndexDefault);
                 self.profile.profileAdvancedSearch().PageSize(pageSize ? pageSize : self.pageSizeDefault);
                 if (industryId) {
                     self.profile.profileAdvancedSearch().IndustryIds().push(industryId);
                 }
                 if (countryId) {
                     self.profile.profileAdvancedSearch().CountryIds().push(countryId);
                 }
                 if (categoryId) {
                     self.profile.profileAdvancedSearch().CategoryIds().push(categoryId);
                 }
                 if (technologyId) {
                     self.profile.profileAdvancedSearch().TechnologyIds().push(technologyId);
                 }
             }
                 //set view mode to list so can profiles be loaded
             else {
                 self.profile.profileViewMode("list");
             }
             self.profile.loadProfilesAdvancedSearchAll();
             //reset alert: you are not allowed...
             self.profile.tableOfProfilesVisible(true);
             self.profile.youAreNotAllowedAlertVisible(false);
             self.render("experts");
         });

         this.get("#/Companies/?", function() {
             self.route("companies");
             self.searchModel("Companies");
             if (self.company.companyViewMode() != "advancedSearch") {
                 self.company.resetSearchModel();
                 var id = this.params.id;
                 var mode = this.params.mode;
                 var pageIndex = this.params.pageIndex;
                 var pageSize = this.params.pageSize;
                 var industryId = this.params.industryId;
                 var countryId = this.params.countryId;
                 self.company.workingCompanyId(id);
                 //MODE
                 // if mode is not defined in route then profileViewMode has value: "list"
                 if (!mode) {
                     self.company.companyViewMode("list");
                 } else {
                     self.company.companyViewMode(mode);
                 }
                 //if for example u go to mylist from menu then to list from menu and go back,u haven't clicked on menu to set UserId to 1,so u have to set that here in the route
                 if (self.company.companyViewMode() == "myList") {
                     self.company.companyAdvancedSearch().UserId(1);
                 }
                 self.company.companyAdvancedSearch().PageIndex(pageIndex ? pageIndex : self.pageIndexDefault);
                 self.company.companyAdvancedSearch().PageSize(pageSize ? pageSize : self.pageSizeDefault);
                 if (industryId) {
                     self.company.companyAdvancedSearch().IndustryIds().push(industryId);
                 }
                 if (countryId) {
                     self.company.companyAdvancedSearch().CountryIds().push(countryId);
                 }
             } else {
                 self.company.companyViewMode("list");
             }
             self.company.loadCompaniesAdvancedSearchAll();
             //reset alert: you are not allowed...
             self.company.tableOfCompaniesVisible(true);
             self.company.youAreNotAllowedAlertVisible(false);
             self.render("companies");
         });


         this.get("#/Positions/?", function() {
             self.route("Positions");
             self.searchModel("Positions");
             if (self.position.positionViewMode() != "advancedSearch") {
                 self.position.resetSearchModel();
                 var id = this.params.id;
                 var mode = this.params.mode;
                 var pageIndex = this.params.pageIndex;
                 var pageSize = this.params.pageSize;
                 var countryId = this.params.countryId;
                 var categoryId = this.params.categoryId;
                 var technologyId = this.params.technologyId;
                 var companyId = this.params.companyId;
                 self.position.workingPositionId(id);
                 //MODE
                 // if mode is not defined in route then profileViewMode has value: "list"
                 if (!mode) {
                     self.position.positionViewMode("list");
                 } else {
                     self.position.positionViewMode(mode);
                 }
                 //if for example u go to mylist from menu then to list from menu and go back,u haven't clicked on menu to set UserId to 1,so u have to set that here in the route
                 if (self.position.positionViewMode() == "myList") {
                     self.position.positionAdvancedSearch().UserId(1);
                 }
                 self.position.positionAdvancedSearch().PageIndex(pageIndex ? pageIndex : self.pageIndexDefault);
                 self.position.positionAdvancedSearch().PageSize(pageSize ? pageSize : self.pageSizeDefault);
                 if (countryId) {
                     self.position.positionAdvancedSearch().CountryIds().push(countryId);
                 }
                 if (categoryId) {
                     self.position.positionAdvancedSearch().CategoryIds().push(categoryId);
                 }
                 if (technologyId) {
                     self.position.positionAdvancedSearch().TechnologyIds().push(technologyId);
                 }
                 if (companyId) {
                     self.position.positionAdvancedSearch().CompanyProfileIds().push(companyId);
                 }
             } else {
                 self.position.positionViewMode("list");
             }
             self.position.loadPositionsAdvancedSearchAll();
             //reset alert: you are not allowed...
             self.position.tableOfPositionsVisible(true);
             self.position.youAreNotAllowedAlertVisible(false);
             self.render("Positions");
         });

         this.get("#/Messages/?", function() {
             self.route("messages");

             self.folder.resetSearchModel();
             var folderId = this.params.folderId;
             var messageId = this.params.messageId;
             var mode = this.params.mode;
             self.folder.messageViewMode(mode);
             self.folder.folderId(folderId);
             self.folder.messageId(messageId);

             self.folder.loadFolders();
             //self.folder.setInboxOnStart();
             self.render("messages");
         });

         this.get("#/Education/List/", function() {
             self.route("education");
             var pageIndex = this.params.pageIndex;
             var pageSize = this.params.pageSize;
             var search = this.params.search;
             self.education.loadEducations(pageIndex, pageSize, search);
             self.render("education");
         });
         this.get("#/Categories/List/", function() {
             self.route("categories");
             var pageIndex = this.params.pageIndex;
             var pageSize = this.params.pageSize;
             var search = this.params.search;
             self.category.loadCategories(pageIndex, pageSize, search);
             self.render("categories");
         });
         this.get("#/Countries/List/", function() {
             self.route("countries");
             var pageIndex = this.params.pageIndex;
             var pageSize = this.params.pageSize;
             var search = this.params.search;
             self.country.loadCountries(pageIndex, pageSize, search);
             self.render("countries");
         });
         this.get("#/Technologies/List/", function() {
             self.route("technologies");
             var pageIndex = this.params.pageIndex;
             var pageSize = this.params.pageSize;
             var search = this.params.search;
             self.technology.loadTechnologies(pageIndex, pageSize, search);
             self.render("technologies");
         });
         this.get("#/Languages/List/", function() {
             self.route("languages");
             var pageIndex = this.params.pageIndex;
             var pageSize = this.params.pageSize;
             var search = this.params.search;
             self.language.loadLanguages(pageIndex, pageSize, search);
             self.render("languages");
         });
     }).run('#/');

 }